package at.gv.bmwf.fons.model.ontology.sources;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class FileDataSource extends AbstractDataSource {
	private final File tboxFile, aboxFile;
	
	public FileDataSource (File tbox, File abox) {
		this.tboxFile = tbox;
		this.aboxFile = abox;
	}

	@Override
	public OntModel createTBox() {
		if (tboxFile != null) {
			OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
			try {
				model.read(new FileInputStream(tboxFile), null, "TTL");
				return model;
			} catch (FileNotFoundException e) {
				throw new IllegalArgumentException(e);
			}
		}
		return super.createTBox();
	}

	@Override
	public OntModel createABox() {
		if (aboxFile != null) {
			OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
			try {
				model.read(new FileInputStream(aboxFile), null, "TTL");
				return model;
			} catch (FileNotFoundException e) {
				throw new IllegalArgumentException(e);
			}
		}
		return super.createABox();
	}

}
